﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameViewer.Core
{
    public class LogManager : Singleton<LogManager>
    {
        private Dictionary<string, Log> mLogs = new Dictionary<string,Log>();
        private Log mDefaultLog;

        public LogManager()
        {
        }

        public Log GetDefaultLog()
        {
            return mDefaultLog;
        }

        public Log SetDefaultLog(Log newLog)
        {
            Log oldLog = mDefaultLog;
            mDefaultLog = newLog;
            return oldLog;
        }

        public Log GetLog(string name)
        {
            if (mLogs.ContainsKey(name))
            {
                return mLogs[name];
            }
            else
            {
                return null;
            }
        }

        public Log CreateLog(String name, bool defaultLog, bool debuggerOutput, 
            bool suppressFileOutput)
        {
            Log newLog = new Log(name, debuggerOutput, suppressFileOutput);

            if (mDefaultLog == null || defaultLog)
            {
                mDefaultLog = newLog;
            }
            mLogs.Add(name, newLog);

            return newLog;
        }

        public void LogMessage(string message)
        {
            LogMessage(message, LogMessageLevel.LML_NORMAL, true);
        }

        public void LogMessage(string message, LogMessageLevel lml)
        {
            LogMessage(message, lml, true);
        }

        public void LogMessage(string message, LogMessageLevel lml, bool maskDebug)
        {
            if (mDefaultLog != null)
            {
                mDefaultLog.LogMessage(message, lml, maskDebug);
            }
        }

    }
}
